#include<bits/stdc++.h>
#define ll long long
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=5e3+5,M=1e6+5,inf=(1LL<<30)-1,mod=998244353;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
int n,a[N];
int st[N][17],lg[N];
inline int get(int l,int r){
	if(l>r)swap(l,r);
	int p=lg[r-l+1];
	return min(st[l][p],st[r-(1<<p)+1][p]);
}
int dp[N][N];
inline int gets(int x,int y){
	if(x<0||y<0)return 0;
	return dp[x][y];
}
inline int got(int l,int r,int Ll,int Rr){
	if(l>r||Ll>Rr)return 0;
	return Red(Add(gets(r,Rr),gets(l-1,Ll-1)),Add(gets(r,Ll-1),gets(l-1,Rr)));
}
int le[N];
inline void Main(){
	n=read();
	repn(i)a[i]=n-read()+1;
	lg[0]=-1;
	repn(i)st[i][0]=a[i],lg[i]=lg[i>>1]+1;
	rep(p,1,15)rep(i,1,n-(1<<p)+1)st[i][p]=min(st[i][p-1],st[i+(1<<p-1)][p-1]);
	rep(i,0,n)dp[0][i]=1;
	repn(i){
		repn(j){
			while(le[j]<i&&(a[j]>get(le[j]+1,i)||a[j]>get(le[j]+1,j)))le[j]++;
			dp[i][j]=got(le[j],i-1,0,j-1);		
		}
		rep(j,0,n)add(dp[i][j],Red(Add(gets(i,j-1),gets(i-1,j)),gets(i-1,j-1)));
	}
	cout <<got(n,n,1,n);
}
signed main(){
	freopen("after.in","r",stdin);
	freopen("after.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}
